<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/9/29
 * Time: 17:15
 */
namespace app\admin\model;
use think\Db;
use think\Model;
class SalesmanModel extends Model
{
    protected $name = 'work_user';

    public function getSalesmanData($map,$Nowpage, $limits){
        return $this->where($map)
            ->field('user_id,user_phone,user_name,user_image,user_mynum,user_job,user_status,user_money,user_time')
            ->page($Nowpage,$limits)
            ->select();
    }

    public function getSalesmanCount($map){
        return $this->where($map)->count();
    }

    public function memberState($id,$num){
        if($num == 2){
            $msg = '禁用';
        }else{
            $msg = '启用';
        }
        Db::startTrans();// 启动事务
        try{
            $this->where ('user_id' , $id)->setField (['user_status' => $num]);
            Db::commit();// 提交事务
        }catch( \Exception $e){
            Db::rollback ();//回滚事务
            return ['code' => 100, 'data' => '', 'msg' => $msg.'失败'];
        }
    }
}